package com.yxb.feedback.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yxb.common.core.page.TableDataInfo;
import com.yxb.common.utils.DateUtils;
import com.yxb.common.utils.sql.SqlUtil;
import com.yxb.feedback.domain.FeedbackVo;
import com.yxb.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yxb.feedback.mapper.FeedbackMapper;
import com.yxb.feedback.domain.Feedback;
import com.yxb.feedback.service.IFeedbackService;

import static com.yxb.common.utils.SecurityUtils.getUserId;

/**
 * 平台留言反馈Service业务层处理
 * 
 * @author 林德炫
 * @date 2025-03-27
 */
@Service
public class FeedbackServiceImpl implements IFeedbackService 
{
    @Autowired
    private FeedbackMapper feedbackMapper;

    @Autowired
    private SysUserMapper sysUserMapper;
    /**
     * 查询平台留言反馈
     * 
     * @param feedbackId 平台留言反馈主键
     * @return 平台留言反馈
     */
    @Override
    public Feedback selectFeedbackByFeedbackId(Long feedbackId)
    {
        return feedbackMapper.selectFeedbackByFeedbackId(feedbackId);
    }

    /**
     * 查询平台留言反馈列表
     * 
     * @param feedback 平台留言反馈
     * @return 平台留言反馈
     */
    @Override
    public List<FeedbackVo> selectFeedbackList(Feedback feedback)
    {
        List<FeedbackVo> feedbackVoList = new ArrayList<>();
        List<Feedback> feedbackList = feedbackMapper.selectFeedbackList(feedback);

        for (Feedback feedback1 : feedbackList) {
            FeedbackVo feedbackVo = new FeedbackVo();
            feedbackVo.setFeedbackId(feedback1.getFeedbackId());
            feedbackVo.setFeedbackContent(feedback1.getFeedbackContent());
            feedbackVo.setCreateTime(feedback1.getCreateTime());
            feedbackVo.setMessageContent(feedback1.getMessageContent());
            feedbackVo.setUserName(feedback1.getUserName());
            feedbackVo.setUserRole(feedback1.getUserRole());
            feedbackVo.setSenderId(feedback1.getSenderId());
            feedbackVo.setAvatar(sysUserMapper.selectAvatarByUserId(feedbackVo.getSenderId()));
            feedbackVoList.add(feedbackVo);
        }
        return feedbackVoList;
    }

//    查询我的留言反馈列表
    @Override
    public List<FeedbackVo> selectMyFeedback(Feedback feedback) {
        List<FeedbackVo> feedbackVoList = new ArrayList<>();
        List<Feedback> feedbackList = feedbackMapper.selectMyFeedback(feedback);
        for (Feedback feedback1 : feedbackList) {
            FeedbackVo feedbackVo = new FeedbackVo();
            feedbackVo.setFeedbackId(feedback1.getFeedbackId());
            feedbackVo.setFeedbackContent(feedback1.getFeedbackContent());
            feedbackVo.setCreateTime(feedback1.getCreateTime());
            feedbackVo.setMessageContent(feedback1.getMessageContent());
            feedbackVo.setUserName(feedback1.getUserName());
            feedbackVo.setUserRole(feedback1.getUserRole());
            feedbackVo.setSenderId(feedback1.getSenderId());
            feedbackVo.setAvatar(sysUserMapper.selectAvatarByUserId(feedbackVo.getSenderId()));
            feedbackVoList.add(feedbackVo);
        }
        return feedbackVoList;
    }



    /**
     * 新增平台留言反馈
     * 
     * @param feedback 平台留言反馈
     * @return 结果
     */
    @Override
    public int insertFeedback(Feedback feedback)
    {
        feedback.setCreateTime(DateUtils.getNowDate());
        return feedbackMapper.insertFeedback(feedback);
    }

    /**
     * 修改平台留言反馈
     * 
     * @param feedback 平台留言反馈
     * @return 结果
     */
    @Override
    public int updateFeedback(Feedback feedback)
    {
        return feedbackMapper.updateFeedback(feedback);
    }

    /**
     * 批量删除平台留言反馈
     * 
     * @param feedbackIds 需要删除的平台留言反馈主键
     * @return 结果
     */
    @Override
    public int deleteFeedbackByFeedbackIds(Long[] feedbackIds)
    {
        return feedbackMapper.deleteFeedbackByFeedbackIds(feedbackIds);
    }

    /**
     * 删除平台留言反馈信息
     * 
     * @param feedbackId 平台留言反馈主键
     * @return 结果
     */
    @Override
    public int deleteFeedbackByFeedbackId(Long feedbackId)
    {
        return feedbackMapper.deleteFeedbackByFeedbackId(feedbackId);
    }
}
